{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2d1a73ab",
   "metadata": {},
   "source": [
    "# Tabularize time series\n",
    "\n",
    "In this assignment, your task is to convert **time series data** into a **tabular data set**.\n",
    "\n",
    "You need to create suitable input features from a time series containing weekly sales to be able to forecast sales for the next week.\n",
    "\n",
    "To prepare the dataset for this assignment, please follow the guidelines in the notebook `02-create-online-retail-II-datasets.ipynb` in the `01-Create-Datasets` folder."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f53976d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2009-12-06</th>\n",
       "      <td>213000.35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-12-13</th>\n",
       "      <td>195810.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-12-20</th>\n",
       "      <td>182396.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-12-27</th>\n",
       "      <td>22007.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-03</th>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                sales\n",
       "week                 \n",
       "2009-12-06  213000.35\n",
       "2009-12-13  195810.04\n",
       "2009-12-20  182396.74\n",
       "2009-12-27   22007.77\n",
       "2010-01-03       0.00"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load weekly sales dataset\n",
    "\n",
    "filename = \"../../Datasets/online_retail_dataset.csv\"\n",
    "\n",
    "df = pd.read_csv(\n",
    "    filename,\n",
    "    usecols=[\"week\", \"United Kingdom\"],\n",
    "    parse_dates=[\"week\"],\n",
    "    index_col=[\"week\"],\n",
    ")\n",
    "\n",
    "df.columns = ['sales']\n",
    "\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cdfe9415",
   "metadata": {},
   "source": [
    "# Data analysis\n",
    "\n",
    "First, explore the time series.\n",
    "\n",
    "## Plot time series"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ceabd79",
   "metadata": {},
   "source": [
    "## Missing data\n",
    "\n",
    "Check if there are missing values in the time series."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c484bca",
   "metadata": {},
   "source": [
    "## Missing timestamps\n",
    "\n",
    "Check if there are missing timestamps in the index."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "444ca303",
   "metadata": {},
   "source": [
    "## Seasonality\n",
    "\n",
    "Does the time series show any obvious seasonal pattern?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e81565cb",
   "metadata": {},
   "source": [
    "# Feature engineering\n",
    "\n",
    "Now, let's begin to tabularize the data."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20ae8079",
   "metadata": {},
   "source": [
    "## Split data\n",
    "\n",
    "Separate the data into training and testing sets, leaving the data after the last week of September to evaluate the forecasts, that is, in the testing set."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "820803d5",
   "metadata": {},
   "source": [
    "## Naive forecast\n",
    "\n",
    "Predict sales in the next week (t) as the value of sales in the previous week (t-1)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4058260e",
   "metadata": {},
   "source": [
    "## Machine Learning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4957673a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fsml",
   "language": "python",
   "name": "fsml"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
